package com.augurit.gzcgwsp.ssgd.qx.web;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import net.sf.json.JSONObject;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.jbpm.api.ProcessEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;
import com.augurit.common.base.action.BaseAction;
import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.form.ResultForm;
import com.augurit.common.syscode.service.ISysCodeService;
import com.augurit.common.syscode.web.form.SysCodeForm;
import com.augurit.common.system.util.WebContextUtils;
import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.printDoc.service.IYwPrintDocService;
import com.augurit.gzcgwsp.printDoc.web.form.YwPrintDocForm;
import com.augurit.gzcgwsp.sendNotice.entity.YwPublicOpinions;
import com.augurit.gzcgwsp.sendNotice.service.IYwPublicOpinionsService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceForWbService;
import com.augurit.gzcgwsp.ssgd.entity.YwRqSsgdSqb;
import com.augurit.gzcgwsp.ssgd.qx.service.IYwRqSsgdSqbQxService;
import com.augurit.gzcgwsp.ssgd.web.form.YwRqSsgdSqbForm;
import com.augurit.gzcgwsp.wfex.app.doc.IOaDocCodeServiceEX;
import com.augurit.gzcgwsp.wfex.bi.service.IWfBusTemplateServiceEX;
import com.augurit.gzcgwsp.wfex.bi.service.IWfTemplateAttachmentRefServiceEX;
import com.augurit.gzcgwsp.wfex.bi.web.form.WfTemplateAttachmentRefFormEX;
import com.augurit.gzcgwsp.wfex.common.service.IWfServiceEX;
import com.augurit.gzcgwsp.wfex.common.util.WfUtilsEX;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.wf.bi.service.IWfBusTemplateService;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.bi.web.form.WfBusTemplateForm;
import com.augurit.wf.common.constant.WfConstant;
import com.augurit.wf.common.entity.Jbpm4HistTask;
import com.augurit.wf.common.form.WfBusSaveResult;
import com.augurit.wf.common.service.IWfBusClientService;
import com.augurit.wf.common.service.IWfService;
import com.augurit.wf.common.util.WfUtils;
import com.augurit.wf.common.web.WfBusClientAction;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "yw-rq-ssgd-sqb-qx.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/gzcgwsp/ssgd/YwRqSsgdSqb/qx/YwRqSsgdSqb.jsp"),
	@Result(name = CrudActionSupport.INPUT, location = "/gzcgwsp/ssgd/YwRqSsgdSqb/qx/YwRqSsgdSqbQx-input.jsp"),
    @Result(name = WfConstant.PRINT, location = WfConstant.PRINT_JSP),
    @Result(name = WfConstant.PRINT_DIR, location = WfConstant.PRINT_DIR_JSP),
    @Result(name = WfConstant.MAKE_DOCUMENT, location = "/gzcgwsp/wfex/client/common/qumake-noline-document.jsp")
})
public class YwRqSsgdSqbQxAction extends WfBusClientAction<YwRqSsgdSqbForm>{
	private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Autowired
    private IWfService wfService;
	@Autowired
	private IYwRqSsgdSqbQxService ywRqSsgdSqbQxService;
	@Autowired
	private IYwComQyxxService qyxxService;
    @Autowired
    private IWfBusTemplateService wfBusTemplateService;
    @Autowired
    private IWfTemplateAttachmentRefServiceEX wfTemplateAttachmentRefServiceEX;
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private ISysCodeService syscodeService;
    @Autowired
	private IYwPublicOpinionsService ywPublicOpinionsService;
    @Autowired
    private IOaDocCodeServiceEX oaDocCodeServiceEX;
    @Autowired
	private IYwPrintDocService ywPrintDocService;
    @Autowired
    private IWfServiceEX wfServiceEX;    
    @Autowired
    private IWfBusTemplateServiceEX wfBusTemplateServiceEX;
    
    
	private YwRqSsgdSqbForm form;
	private Long[] checkedIds;
	private Page<YwRqSsgdSqbForm> page = new Page<YwRqSsgdSqbForm>(10);

    /**
     * 保存业务并关联流程实例
     */
    public String wfBusSave() {
    	try{
        if (form.getQyid() == null) {
            YwComQyxxForm qyxxForm = qyxxService.getFormBySqdw(form.getSqdw(),form.getTemplateCode());
            if (qyxxForm != null) {
                WfUtils.renderWfFailtureJson("该企业名称已经存在，请点击选择企业从企业列表中选择该企业！");
                return null;
            }
        }
        LoginUserForm user = (LoginUserForm)getSession().getAttribute(WebContextUtils.SES_LOGIN_USER);
        String orgName = user.getOrg().getOrgName();
		if(StringUtils.isNotBlank(orgName)){//把所属区保存到WfBusInstance表的busMemo2字段里面
			form.setSsq(orgName.substring(0,3));	
		}
        WfBusInstanceTaskForm task = this.wfBusSave((IWfBusClientService)ywRqSsgdSqbQxService, form, YwRqSsgdSqb.class.getSimpleName());
        String durationExpression = wfServiceEX.getProcDueExpressIonByTaskInstDbid(task.getTaskInstDbid());
        if (form.getDfsj() == null) {            
            Date dfsj = wfServiceEX.calculateDueDate(form.getLarq(), durationExpression);
            form.setDfsj(dfsj);
            this.save();
        }
        String isYsl = super.getParameter("isYsl");
        if (StringUtils.isNotBlank(isYsl) && "1".equals(isYsl)) {
        	String executionId =  processEngine.getHistoryService().createHistoryTaskQuery().taskId(task.getTaskInstDbid().toString()).uniqueResult().getExecutionId();
            processEngine.getExecutionService().jumpToActivity(executionId, "cksa");
            form.setYsl(null);
            ywRqSsgdSqbQxService.changeYslState(form.getId(), null,"");
        }
        WfUtils.renderWfBusSaveJson(task, form);
    	}catch (Exception e) {
    		WfUtils.renderWfFailtureJson("请检查输入内容长度是否过大!");
    		e.printStackTrace();
    	}
        return null;
        
    }
    
    /*
    public String wfSendEndAuto() throws Exception {
        WfBusInstanceTaskForm task = this.wfBusSave((IWfBusClientService)ywRqSsgdSqbQxService, form, YwRqSsgdSqb.class.getSimpleName());
        processEngine.getExecutionService().jumpToActivity(task.getExecutionId(), "end");
        WfUtils.renderWfBusSaveJson(task, form);
        return null;
    }
    */
    
    public String wfBusYslTuih() throws Exception {
    	try {
			ywRqSsgdSqbQxService.wfBusYslTuih(form, this.getLoginUser());
			WfBusSaveResult result = new WfBusSaveResult(true, null);
			result.setTask(new WfBusInstanceTaskForm());
			Struts2Utils.renderJson(result);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
        return null;
    }
    
    public String printcz() throws Exception {
    	form.setCbyw(form.getCbyw().replace("区县", "").replace("区", ""));
    	String taskId=getRequest().getParameter("taskInstDbid");
    	String activName="";
		if(StringUtils.isNotBlank(taskId)){
		  	WfBusInstanceTaskForm instance = wfService.getWfBusInstanceTaskById(Long.valueOf(taskId), this.getLoginUserName());
			activName=instance.getActivityName();
		    getRequest().setAttribute("activName", activName);
		}else{
			 getRequest().setAttribute("activName", "");
		}
		//设置反对意见的内容
		 String fdOpinionsConent="";
		  Page<YwPublicOpinions> fdOpinionsPage = new Page<YwPublicOpinions>(10000);
		  Page<YwPublicOpinions> fdOpinionsPage2 = ywPublicOpinionsService.getFdOpinionsByAcceptNo(fdOpinionsPage,form.getAcceptNo());
		  List<YwPublicOpinions> list=fdOpinionsPage2.getResult();
		  for(YwPublicOpinions opion:list){
			  fdOpinionsConent+=opion.getOpinion()+"\n\r";
			  
		  }
		  //获取总意见数
	        long totalOpinions = ywPublicOpinionsService.getTotalOpinionsByAcceptNo(form.getAcceptNo());
	        form.setTotalOpinions(totalOpinions);
	        //获取满意意见数
	        long fdOpinionsTotal = ywPublicOpinionsService.getFdOpinionsTotalByAcceptNo(form.getAcceptNo());
	        form.setFdOpinionsTotal(fdOpinionsTotal);
		    form.setFdOpinionsConent(fdOpinionsConent);
    	if(form.getId() != null && form.getId() > 0){
    		List<YwPrintDocForm> ywPrintDocFormList = ywPrintDocService.get(form.getTemplateCode(), form.getFileCode(), form.getId());
        	if(ywPrintDocFormList!=null && ywPrintDocFormList.size()>0){
    			return WfConstant.PRINT_DIR;
    		}
    	}
    
        return WfUtilsEX.wfBusPrint(form,form.getId(),activName);
    }
    
    /**
     * 制文
     * @return
     * @throws Exception
     */
    public String makeDocument() throws Exception {
    	String taskId=getRequest().getParameter("taskInstDbid");
    	String activName="";
		if(StringUtils.isNotBlank(taskId)){
		  	WfBusInstanceTaskForm instance = wfService.getWfBusInstanceTaskById(Long.valueOf(taskId), this.getLoginUserName());
			activName=instance.getActivityName();
		    getRequest().setAttribute("activName", activName);
		}else{
			 getRequest().setAttribute("activName", "");
		}
        if (StringUtils.isNotBlank(form.getRedHeadFileId())) {
            String redHeadFilePath = wfBusTemplateServiceEX.getPrintTemplatePath(Long.parseLong(form.getRedHeadFileId()));
            form.setRedHeadFilePath(redHeadFilePath);
        }
         //加载收件通知书里面的附件
		 String isred=getRequest().getParameter("isred");
		 //如果要打印红头
		 if("yes".equals(isred)){
			 String redHeadFilePath = wfBusTemplateServiceEX.getRedFile(form.getTemplateCode());
		      form.setRedHeadFilePath(redHeadFilePath);
		 }
        String templateCode = getTemplateCode();
        if(templateCode != null && templateCode.trim().length() > 0){
            String printTemplatePath = wfBusTemplateServiceEX.getPrintTemplatePath(templateCode, WfTemplateAttachmentRefFormEX.ZHENGWEN_TEMPLATE_TYPE);
            form.setTemplatePath(printTemplatePath);
            WfTemplateAttachmentRefFormEX wfTemplateAttachmentRefFormEX = (WfTemplateAttachmentRefFormEX)wfTemplateAttachmentRefServiceEX.get(Long.parseLong(form.getZhengwenFileId()));
            String zhengwenPath = wfTemplateAttachmentRefFormEX.getFilePath() + "/" + wfTemplateAttachmentRefFormEX.getFileRealName();
            form.setZhengwenPath(zhengwenPath);
            form.setCurDate(DateUtilsEX.convertDate2Chinese(new Date()));
            form.setCurYear(String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
            Long seq=oaDocCodeServiceEX.getQuCurSeqAndAddSeq(templateCode, wfTemplateAttachmentRefFormEX.getFileCode(),
            		form.getId(),this.getLoginUser());
            if(seq.intValue()<10){
	        	  form.setCurSeq("0"+String.valueOf(seq));
	        }else{
	        	  form.setCurSeq(String.valueOf(seq));
	        }
            
            WfUtilsEX.wfBusPrint(form,form.getId(),activName);
            BaseAction.getRequest().setAttribute("seq", form.getCurSeq());
            BaseAction.getRequest().setAttribute("fileCode", wfTemplateAttachmentRefFormEX.getFileCode());
            BaseAction.getRequest().setAttribute("entityId", form.getId());
            BaseAction.getRequest().setAttribute("templateId", wfTemplateAttachmentRefFormEX.getId());
            BaseAction.getRequest().setAttribute("templateFilePath",zhengwenPath);
//            BaseAction.getRequest().setAttribute("busType", OaFawen.class.getSimpleName());
        }
        return WfConstant.MAKE_DOCUMENT;
    }
    
	/**
	 * ��ҳ��ѯ
	 */
	@Override
	public String list() throws Exception {
		ywRqSsgdSqbQxService.search(page, form);
		return SUCCESS;
	}

	/**
	 * �������޸�
	 */
	@Override
	public String input() throws Exception {
        //this.initWfOpinions();
        this.setOpinions();
        getRequest().setAttribute("CurrUserName", this.getLoginUser().getUser().getUserName());
        List<SysCodeForm> ywRqssgdQy = syscodeService.getItems("YW_RQSSGD_QY");
        List<SysCodeForm> ywHbbm = syscodeService.getItems("ALL_HBBM");
        getRequest().setAttribute("ssxzqyList", ywRqssgdQy);
        getRequest().setAttribute("ywhbbmList", ywHbbm);    	
		return INPUT;
	}

	/**
	 * �������������޸ĵ�Form����
	 */
	@Override
	public String save() throws Exception {
		ywRqSsgdSqbQxService.save(form);
		return RELOAD;
	}

	/**
	 * ɾ��һ����¼
	 */
	@Override
	public String delete() throws Exception {
		ywRqSsgdSqbQxService.delete(form.getId());
		return RELOAD;
	}
	
	/**
	 * ɾ�������¼
	 */
	@Override
	public String deleteMore() throws Exception{
		ywRqSsgdSqbQxService.delete(checkedIds);
		return RELOAD;
	}
	
	/**
	 * ׼��ҳ��ģ��
	 */
	@Override
	protected void prepareModel() throws Exception {
		LoginUserForm uform=(LoginUserForm)this.getRequest().getSession().getAttribute("SES_LOGIN_USER");
		String username=uform.getUser().getUserName();
	    String id = super.getParameter("id");
		if(StringUtils.isNotBlank(id)){
			form = ywRqSsgdSqbQxService.get(Long.parseLong(id));
		} else {
			form = new YwRqSsgdSqbForm();
		}
		if(StringUtils.isNotBlank(form.getCbyw())){
			form.setCbyw(form.getCbyw().replace("区县", "").replace("区", ""));
		}		
		form.setCbyw2(form.getCbyw());
		form.setCbyw3(form.getCbyw());
		form.setCbyw4(form.getCbyw());
		if (StringUtils.isNotBlank(form.getAcceptNo())) {
			Page<YwPublicOpinions> publicOpinionsPage = new Page<YwPublicOpinions>(10);//获取十条案件公示意见
			Page<YwPublicOpinions> page2 = ywPublicOpinionsService.getByAcceptNo(publicOpinionsPage,form.getAcceptNo());
	        super.getRequest().setAttribute("page2", page2);
	        
	        //获取总意见数
	        long totalOpinions = ywPublicOpinionsService.getTotalOpinionsByAcceptNo(form.getAcceptNo());
	        form.setTotalOpinions(totalOpinions);
	        //super.getRequest().setAttribute("totalOpinions", totalOpinions);
	        //获取满意意见数
	        long fdOpinionsTotal = ywPublicOpinionsService.getFdOpinionsTotalByAcceptNo(form.getAcceptNo());
	        form.setFdOpinionsTotal(fdOpinionsTotal);
	        //super.getRequest().setAttribute("fdOpinionsTotal", fdOpinionsTotal);
	        //获取反对意见
	        Page<YwPublicOpinions> fdOpinionsPage = new Page<YwPublicOpinions>(10000);
			Page<YwPublicOpinions> fdOpinionsPage2 = ywPublicOpinionsService.getFdOpinionsByAcceptNo(fdOpinionsPage,form.getAcceptNo());
	        super.getRequest().setAttribute("fdOpinionsPage2", fdOpinionsPage2);
        }		

        if (StringUtils.isBlank(form.getAcceptNo())) {
            form.setAcceptNo("11030200XXXX");
        }
        if (StringUtils.isBlank(form.getSjr())) {
            form.setSjr(this.getLoginUser().getUser().getUserName());
        }
        if (StringUtils.isBlank(form.getJbrxm())) {
            form.setJbrxm(this.getLoginUser().getUser().getUserName());
            form.setJbrdh(this.getLoginUser().getUser().getOfficeTel());
        }
        form.setJbrxm2(this.getLoginUser().getUser().getUserName());
        form.setJbrdh2(this.getLoginUser().getUser().getOfficeTel());
        form.setJbrdh(form.getJbrdh2());//xu61增加
        
        form.setSajg(uform.getOrg().getOrgName());
        form.setSajg2(form.getSajg());
        form.setSajg3(form.getSajg());
        form.setSajg4(form.getSajg());
        form.setSajg5(form.getSajg());
        form.setSajg6(form.getSajg());
        form.setQu("("+uform.getOrg().getOrgName().substring(0, 1)+")");
        
        if(form.getLarq() == null){
        	form.setLarq(new Date());
        }        
        form.setLarq2(new Date());
        if (StringUtils.isBlank(form.getCbyw())) {
            WfBusTemplateForm wfBusTemplateForm = wfBusTemplateService.getByTemplateCode(getTemplateCode());
            if (wfBusTemplateForm != null) {
            	form.setCbyw(wfBusTemplateForm.getTemplateName().replace("区县", "").replace("区", ""));
            }
        }

        if (StringUtils.isBlank(form.getCbbm())) {
            form.setCbbm("燃气处");
        }        
        if (form.getSqrq() == null) {
            form.setSqrq(new Date());
        }
        if (form.getSarq() == null) {
            form.setSarq(new Date());
        }
        if (form.getJhsssj() == null) {
            form.setJhsssj(new Date());
        }
        if (form.getJhwcsj() == null) {
            form.setJhwcsj(new Date());
        }
        if (form.getCpsj() == null) {
            form.setCpsj(new Date());
        }
        if (form.getSsgdjssj()==null) {
        	form.setSsgdjssj(new Date());
        }
        if (form.getSsgdkssj() == null) {
        	form.setSsgdkssj(new Date());
        }
        
        if(getTaskInstDbid() != null){
        	this.findJbrspUtil();	//获取审批过程中的意见列表
        	this.findCldspUtil();
        	this.findWldspUtil();
        	
        	this.cpbJbrspUtil();
        	this.cpbCldspUtil();
        	this.cpbWldspUtil();
        }
        
        Locale locale = Locale.getDefault(); 
    	ResourceBundle localResource = ResourceBundle.getBundle("interfaceExchange", locale); 
    	String spdwdh = form.getSpdwdh();
    	System.out.println("spdwdh = "+spdwdh);
    	if(StringUtils.isBlank(spdwdh)){
    		spdwdh = localResource.getString("spdwdh");//公示表中的审批单位  电话
    	}    		
    	super.getRequest().setAttribute("spdwdh", spdwdh);
    	//获取延期天数
    	int yqtsInt = wfServiceEX.getYqtsByProcInstId(super.getProcInstId());
    	form.setYqts(String.valueOf(yqtsInt));
//        if (form.getDfsj() == null) {
//            form.setDfsj(DateUtils.stringToDate(form.getCpsj().toString(), DateUtils.YEAR_MOUTH_DAY_));
//        }
    	
    	//补交告知原因
    	if(form.getBjgzyy()==null){
    		form.setBjgzyy(this.getOpinion("jbrsl"));
    	}
    	//补交告知时间
    	if(form.getBjgzsj()==null){
    		form.setBjgzsj(new Date());
    	}
//    	//受理告知时间
//    	if(form.getBjslsj()==null){
//    		form.setBjslsj(new Date());
//    	}
    	//补交告知发出人
//    	if(form.getBjgzfcr()==null){
//    		form.setBjgzfcr(username);
//    	}
//        //补交告知受理人
//    	if(form.getSldwcbrxm()==null){
//    		form.setSldwcbrxm(username);
//    		
//    	}
    	//补交告知受理地点
    	if(form.getBjsljtdd()==null){
    		form.setBjsljtdd(uform.getOrg().getOrgName());
    	}
    	
    	//答复时间
    	if(StringUtils.isNotBlank(id) && StringUtils.isNotBlank(this.getTemplateCode())){
    		Date date=this.wfServiceEX.getDfsjByTempleteCode(this.getTemplateCode(),Long.valueOf(id));
    		form.setDfsj(date);
    	}
    	if(StringUtils.isNotBlank(this.getTemplateCode())){
    		form.setBranch(this.getTemplateCode());
    	}
	}
	//打印 呈批表经办人意见
	private void cpbJbrspUtil(){
		String names = "'jbrsl' , 'jbrsj'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer jbrspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
				jbrspYj.append(list.get(i).getHandleComments()).append("\n")
				.append("    ").append(list.get(i).getAssigneeName()).append("\n")
				.append(simpleDateFormat.format(list.get(i).getHandleCommentsTime())).append("\n");
			   break;
			}
		}
		form.setCpbJbryj(jbrspYj.toString());
	}
	//打印  呈批表 处领导意见
	private void cpbCldspUtil(){
		String names = "'cfgldsh' , 'czgldsh'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer cldspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
				cldspYj.append(list.get(i).getHandleComments()).append("\n")
				.append("    ").append(list.get(i).getAssigneeName()).append("\n")
				.append(simpleDateFormat.format(list.get(i).getHandleCommentsTime())).append("\n");
				break;
			}
		}
		form.setCpbCldyj(cldspYj.toString());
	}
	//打印  呈批表 委领导意见
	private void cpbWldspUtil(){
		String names = "'wfgldsh' , 'wzgldsp'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer wldspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
			wldspYj.append(list.get(i).getHandleComments()).append("\n")
			.append("    ").append(list.get(i).getAssigneeName()).append("\n")
			.append(simpleDateFormat.format(list.get(i).getHandleCommentsTime())).append("\n");
			break;
			}
		}
		form.setCpbWldyj(wldspYj.toString());
	}
	
	
	/**
	 * 窗口导入前检查
	 * @return
	 * @throws Exception
	 */	
	public String checkImportData() throws Exception{
        String id=getRequest().getParameter("id");
        String templateCode=getRequest().getParameter("templateCode");
        String qyid=getRequest().getParameter("qyid");
        String contextpath=getRequest().getSession().getServletContext().getRealPath("");
        //先查询收件材料是否存在
        boolean flag=this.ywRqSsgdSqbQxService.checkData(templateCode,"申请表",Long.valueOf(id),Long.valueOf(qyid));
        if(flag){
        	
        }else{
            getResponse().getWriter().print("fileNotExist");
        }
	    
	    return null;
	}
	
	   /**
     * 窗口收案环节导入数据
     */
    public String  importData() throws Exception{
        Map map=getMapByRequest(getRequest());
        String contextPath=getRequest().getSession().getServletContext().getRealPath("");
        map.put("contextPath", contextPath);
        map.put("id", form.getId());
        map.put("filename", "申请表");
        String result=this.ywRqSsgdSqbQxService.importData(form,map);
        if(result==null)
        	getResponse().getWriter().print("");
        else
        	getResponse().getWriter().print(result);
        
        return null;
    }
    
	 private  Map getMapByRequest(HttpServletRequest request) {
	        Map<String, String> map = new HashMap<String, String>();
	        Enumeration enu = request.getParameterNames();
	        while(enu.hasMoreElements()) {   
	            String paraName = (String)enu.nextElement();   
	            String paraValue = request.getParameter(paraName).trim(); 
	            //if(paraValue!=null && !"".equals(paraValue)){
	                map.put(paraName, paraValue);
	            //}           
	        }
	                
	        return map;
	    }
	    /**
	     *获取返回后导入的数据
	     * @return
	     * @throws IOException 
	     */
	    public String getResultImportData () throws IOException{
	       if(form!=null && form.getId()!=null){
	           JSONObject jsonObject = JSONObject.fromObject(form); 
	           getResponse().getWriter().print(jsonObject.toString());
	       }
	        return null;
	    }
	    
	/**
	 * from加载	经办人审批意见列表工具方法
	 */
	private void findJbrspUtil(){
		String names = "'jbrsl' , 'jbrsj'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer jbrspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
				jbrspYj.append(list.get(i).getHandleComments());
				form.setJbrslsj(list.get(i).getHandleCommentsTime());
				form.setJbrslxm(list.get(i).getAssigneeName());
				break;
			}
		}
		form.setJbrsl(jbrspYj.toString());
	}
	/**
	 * from加载	处领导审批意见列表工具方法
	 */
	private void findCldspUtil(){
		String names = "'cfgldsh' , 'czgldsh'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer cldspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
				cldspYj.append(list.get(i).getHandleComments());
				form.setCldspsj(list.get(i).getHandleCommentsTime());
				form.setCldspxm(list.get(i).getAssigneeName());
				break;
		   }
		}
		form.setCldsp(cldspYj.toString());
	}
	/**
	 * from加载	委领导审批意见列表工具方法
	 */
	private void findWldspUtil(){
		String names = "'wfgldsh' , 'wzgldsp'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer wldspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
				wldspYj.append(list.get(i).getHandleComments());
				form.setWldspsj(list.get(i).getHandleCommentsTime());
				form.setWldspxm(list.get(i).getAssigneeName());
				break;
			}
		}
		form.setWldsp(wldspYj.toString());
	}
	
	public YwRqSsgdSqbForm getModel() {
		return form;
	}
	
	public Long[] getCheckedIds() {
		return checkedIds;
	}

	public void setCheckedIds(Long[] checkedIds) {
		this.checkedIds = checkedIds;
	}
	
	public Page<YwRqSsgdSqbForm> getPage() {
		return page;
	}


	public void setPage(Page<YwRqSsgdSqbForm> page) {
		this.page = page;
	}
	
	/**
     * 获取所有的意见，填写到公示表中,点击公示表意见列表里面的【更多】的时候
     * @return
     * @throws Exception
     */
	public void getAllOpinions(){
		String acceptNo = super.getParameter("acceptNo");
		Page<YwPublicOpinions> publicOpinionsPage = new Page<YwPublicOpinions>(10);
		publicOpinionsPage.setPageSize(100000);
		Page<YwPublicOpinions> page2 = ywPublicOpinionsService.getByAcceptNo(publicOpinionsPage,acceptNo);
		this.renderJson(new ResultForm(false, page2.getResult()));
	}
	
//	/**
//     * 改变公示状态
//     * @return
//     * @throws Exception
//     */
//	public void changeIsAjgsById(){
//		String idTemp = super.getParameter("id");
//		String state = super.getParameter("state");
//		Long id = Long.parseLong(idTemp);
//		ywRqSsgdSqbQxService.changeIsAjgsById(state,id);
//		this.renderJson(new ResultForm(false,"true"));
//	}
	
	/**
     * 通过id改变SendAcceptNotice或者SendNotice状态
     * @return
     * @throws Exception
     */
	public void changeSendAcceptNoticeOrSendNoticeById(){
		String idTemp = super.getParameter("id");
		Long id = Long.parseLong(idTemp);
		String templateCode = super.getParameter("templateCode");
		String sendYqNotice = super.getParameter("sendYqNotice");
		String sendAcceptNotice = super.getParameter("sendAcceptNotice");
		ywRqSsgdSqbQxService.changeSendAcceptNoticeOrSendNoticeById(id, sendYqNotice,sendAcceptNotice,templateCode);
	}
}
